package inet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * create by yongli on 2020-07-31 21:18
 * 自由写代码
 */

public class SocketServerTest {
    public static void main(String[] args) throws IOException {

        try {
            ServerSocket serverSocket = new ServerSocket(6780);
            Socket socket = serverSocket.accept();
            System.out.println("I received a request");
            BufferedReader bf = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String request;
            // 会被操作系统处理.
            while ((request = bf.readLine()) != null) {
                if ("Done".equals(request)) {
                    break;
                }
                System.out.println(request);
            }
            System.out.println("It's end");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
